package com.iflytek.iot.web.utils;

import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.Map;

/**
 * @author yu 2019/3/20.
 */
public class JacksonUtils {

    private static ObjectMapper objectMapper = new ObjectMapper();

    /**
     * 将对象转换成map
     * @param object
     * @return
     */
    public static Map<Object,Object> toMap(Object object){
        return objectMapper.convertValue(object, Map.class);
    }

    /**
     * 将map转转成对对象
     * @param map
     * @param tClass
     * @param <T>
     * @return
     */
    public static <T> T mapToBean(Map map,Class<T> tClass){
        return objectMapper.convertValue(map,tClass);
    }

}
